package cn.lili.modules.serviceimpl;

import cn.lili.modules.entity.AppUsersFans;
import cn.lili.modules.mapper.AppUsersFansMapper;
import cn.lili.modules.service.AppUsersFansService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author:xiangqian
 * @date: 2024/3/8 20:05
 */
@Service
public class AppUsersFansServiceImpl extends ServiceImpl<AppUsersFansMapper, AppUsersFans> implements AppUsersFansService {

    /**
     * 是否关注查询
     *
     * @param openid 当前用户openID
     * @param fanId  当前作者ID
     * @return 0没有 1有
     */
    @Override
    public Long getAppUsersFansCount(String openid, String fanId) {
        if (openid == null) {
            return 0L;
        }
        LambdaQueryWrapper<AppUsersFans> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AppUsersFans::getUser_id, openid);
        queryWrapper.eq(AppUsersFans::getFan_id, fanId);
        return this.count(queryWrapper);
    }

    @Override
    public AppUsersFans getAppUsersFans(String openid, String fanId) {
        LambdaQueryWrapper<AppUsersFans> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AppUsersFans::getUser_id, openid);
        queryWrapper.eq(AppUsersFans::getFan_id, fanId);
        queryWrapper.last("limit 1");
        return this.getBaseMapper().selectOne(queryWrapper);
    }
}
